﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace Shipwire.Messages
{
    [XmlRootAttribute("RateRequest")]
    public class RateRequest : ShipwireRequest
    {
        public RateRequest()
        {
        }

        public RateRequest(Server server, string emailAddress, string password) : base(server, emailAddress, password)
        {
        }

        public OrderRateRequest Order { get; set; }
    }

    public class OrderRateRequest
    {
        public OrderRateRequest()
        {
        }

        [XmlAttribute("id")]
        public string Id { get; set; }
        public Warehouse? Warehouse { get; set; }
        public AddressInfo AddressInfo { get; set; }
        [XmlElement("Item")]
        public OrderItem[] Items { get; set; }
    }

    public class AddressInfo
    {
        public AddressInfo()
        {
            Type = "ship";
        }

        [XmlAttribute("type")]
        public string Type { get; set; }
        public string Full { get; set; }
        public ShipwireName Name { get; set; }
        public string Company { get; set; }
        public string Address1 { get; set; }
        public string Address2 { get; set; }
        public string Address3 { get; set; }
        public string City { get; set; }
        public string State { get; set; }
        public string Country { get; set; }
        public string Zip { get; set; }
        
        public bool? Commercial { get; set; }
        public bool PoBox { get; set; }

        public string Phone { get; set; }
        public string Email { get; set; }

        internal void CleanForShipwire()
        {
            // We must remove the Commercial tag if False, as if it is not empty Shipwire will
            // treat the order as commercial.
            if (Commercial == false)
                Commercial = null;
        }
    }

    public class OrderItem
    {
        [XmlAttribute("num")]
        public string Num { get; set; }
        public string Code { get; set; }
        public int Quantity { get; set; }
    }

    public class ShipwireName
    {
        public ShipwireName()
        {
        }

        public ShipwireName(string full)
        {
            Full = full;
        }

        public string Full { get; set; }
    }
}
